// 操作失败
import { Message } from 'element-ui'
import { aesDecrypt } from '@/secret/secret'
import store from '@/store'

export default async (type, result) => {
  switch (type) {
    // 类型不支持
    case '255.0.1': {
      Message({
        type: 'error',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 数据序列化失败
    case '255.0.2': {
      Message({
        type: 'error',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 身份认证失败
    case '255.0.3': {
      Message({
        type: 'error',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      // 关闭连接 重新建立连接
      store.state.socket.webSocket.close()
      // store.dispatch('socket/initWS')
      break
    }
    // 无权限执行此操作
    case '255.0.4': {
      Message({
        type: 'error',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 用户已离线
    case '255.0.5': {
      Message({
        type: 'error',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 会议不存在
    case '255.0.6': {
      Message({
        type: 'error',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      store.commit('conference/set_joinCfData_code_error_msg', aesDecrypt(result.body, store.state.socket.DHSecretKey))
      break
    }
    // 会议需要密码
    case '255.0.7': {
      store.commit('common/set_ifShowInputPassword')
      break
    }
    // 会议密码错误
    case '255.0.8': {
      store.commit('conference/set_joinCfData_password_error_msg', aesDecrypt(result.body, store.state.socket.DHSecretKey))
      break
    }
    // 会议已锁定
    case '255.0.9': {
      store.commit('conference/set_joinCfData_code_error_msg', aesDecrypt(result.body, store.state.socket.DHSecretKey))
      break
    }
    // 已被踢出会议，无法加入
    case '255.0.10': {
      store.commit('conference/set_joinCfData_code_error_msg', aesDecrypt(result.body, store.state.socket.DHSecretKey))
      break
    }
    // 会议已结束
    case '255.0.11': {
      Message({
        type: 'error',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      store.commit('conference/set_joinCfData_code_error_msg', aesDecrypt(result.body, store.state.socket.DHSecretKey))
      break
    }
    // 该人员未加入会议，操作失败
    case '255.0.12': {
      Message({
        type: 'error',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 消息发送失败
    case '255.0.13': {
      Message({
        type: 'error',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 会议未开始
    case '255.0.14': {
      Message({
        type: 'info',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 对方已取消视频邀请
    case '255.0.15': {
      Message({
        type: 'info',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 对方已取消语音邀请
    case '255.0.16': {
      Message({
        type: 'info',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 非该通话成员，无权限执行此操作
    case '255.0.17': {
      Message({
        type: 'warning',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 非被呼叫成员，无权限执行此操作
    case '255.0.18': {
      Message({
        type: 'warning',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 非呼叫成员，无权限执行此操作
    case '255.0.19': {
      Message({
        type: 'warning',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 通话已取消
    case '255.0.20': {
      Message({
        type: 'info',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 通话已在进行中
    case '255.0.21': {
      Message({
        type: 'info',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 通话未在进行中
    case '255.0.22': {
      Message({
        type: 'info',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
    // 通话拨打失败，请重试
    case '255.0.23': {
      Message({
        type: 'error',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      store.commit('message/set_videoCallInfo', {
        isInviter: null,
        oppositeID: null
      })
      store.commit('common/set_ifShowVideoInvitation', false)
      store.commit('message/set_videoCallMsgID', null)
      break
    }
    // 通话不存在或已结束
    case '255.0.24': {
      Message({
        type: 'info',
        message: '通话不存在或已结束'
      })
      store.commit('message/set_videoCallInfo', {
        isInviter: null,
        oppositeID: null
      })
      store.commit('common/set_ifShowVideoInvitation', false)
      store.commit('message/set_videoCallMsgID', null)
      break
    }
    // 对方正在通话中
    case '255.0.25': {
      Message({
        type: 'info',
        message: '对方忙线中'
      })
      // 对方忙线时隐藏对话框
      store.commit('message/set_videoCallInfo', {
        isInviter: null,
        oppositeID: null
      })
      store.commit('common/set_ifShowVideoInvitation', false)
      break
    }
    // 对方正在通话中
    case '255.0.26': {
      Message({
        type: 'info',
        message: '对方忙线中'
      })
      // 对方忙线时隐藏对话框
      store.commit('message/set_videoCallInfo', {
        isInviter: null,
        oppositeID: null
      })
      store.commit('common/set_ifShowVideoInvitation', false)
      break
    }
    // 操作失败，请重试
    case '255.0.255': {
      Message({
        type: 'error',
        message: aesDecrypt(result.body, store.state.socket.DHSecretKey)
      })
      break
    }
  }
}
